﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Script.Serialization;
using System.Web.UI;
using RouteMaster;

public partial class jsonBusRoute : Page
{
    MySQLHelper _sql = new MySQLHelper();

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            string from = Request.QueryString["from"];
            string to = Request.QueryString["to"];

            Response.Expires = -1;

            _sql.ReadRoutesDataSet();

            var changes = new RouteItinerary();
            _sql._world._all.IsPossibleRoute(   _sql._world._theStopsById[int.Parse(from)], 
                                                _sql._world._theStopsById[int.Parse(to)], changes);

            //http://weblogs.asp.net/hajan/archive/2010/07/23/javascriptserializer-dictionary-to-json-serialization-and-deserialization.aspx

            var dict = ReportBuilder.ReportToDictionary(changes);

            var builder = new StringBuilder();
            new JavaScriptSerializer().Serialize(dict, builder);
            Response.Write(builder.ToString());
        }
        catch (Exception)
        {

        }
    }
}